package com.example.myapplication;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.ListAdapter;
import android.widget.ListView;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

import java.util.List;

public class Books_Activity extends AppCompatActivity {
    private BookDatabaseHelper dbHelper;
    private ListView listView;
    private ImageView img;
    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_books);
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
            Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
            return insets;
        });
        dbHelper = new BookDatabaseHelper(this);
        listView = findViewById(R.id.listView);
        loadBooks();
        img = findViewById(R.id.imageView3);
        img.setOnClickListener(v->{
            finish();
        });
    }
    private void loadBooks() {
        List<Book> bookList = dbHelper.getAllBooks();
        BookAdapter adapter = new BookAdapter(this, bookList);
        listView.setAdapter(adapter);
    }
}